package com.ynding.spring.idea.ddd.core.service.wechat.service.impl;

import com.ynding.spring.idea.ddd.core.model.wechat.domain.WechatAccount;
import com.ynding.spring.idea.ddd.core.model.wechat.valobj.AssetVO;
import com.ynding.spring.idea.ddd.core.service.wechat.repository.AccountRepository;
import com.ynding.spring.idea.ddd.core.service.wechat.service.TransferService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author ynding
 * @version 2022/9/11
 **/
@Service
@Slf4j
@RequiredArgsConstructor
public class TransferServiceImpl implements TransferService {

    private final AccountRepository accountRepository;

    @Override
    public void transfer(WechatAccount payer, WechatAccount payee, AssetVO asset) {
        payer.withdraw(asset);
        payee.deposit(asset);
        accountRepository.save(payer);
        accountRepository.save(payee);
    }
}
